-
Notifications
You must be signed in to change notification settings - Fork 619
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move v2 metadata models to ecs-agent module #3705
Conversation
e166b21
to
51d3dbd
Compare
} | ||
|
||
// Container health status | ||
type HealthStatus struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a new type which matches the apicontainer.HealthStatus
type that is being used in v2 metadata response currently.
amazon-ecs-agent/agent/api/container/container.go
Lines 111 to 120 in 883211e
type HealthStatus struct { | |
// Status is the container health status | |
Status apicontainerstatus.ContainerHealthStatus `json:"status,omitempty"` | |
// Since is the timestamp when container health status changed | |
Since *time.Time `json:"statusSince,omitempty"` | |
// ExitCode is the exitcode of health check if failed | |
ExitCode int `json:"exitCode,omitempty"` | |
// Output is the output of health check | |
Output string `json:"output,omitempty"` | |
} |
This is being done to decouple metadata response models from API models.
func dockerContainerHealthToV2Health(health apicontainer.HealthStatus) *tmdsv2.HealthStatus { | ||
status := health.Status.String() | ||
if health.Status == apicontainerstatus.ContainerHealthUnknown { | ||
// Skip sending status if it is unknown |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q. did we previously send heath status ContainerHealthUnknown
? If yes, would this be a new change introduced to v2? Also curious how would Since
, ExitCode
and Output
look like when status is ContainerHealthUnknown
: )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good question. No we do not send Status
when container's health status is ContainerHealthUnknown
because the Status
field in apicontainer.HealthStatus
struct is defined with json:"status,omitempty"
.
ContainerHealthUnknown
is the zero value of Status
's type so Status = ContainerHealthUnknown
is skipped when apicontainer.HealthStatus
is marshaled to JSON.
The TestDockerContainerHealthToV2HealthJSON
test in this PR covers this case.
amazon-ecs-agent/agent/api/container/container.go
Lines 111 to 120 in 883211e
type HealthStatus struct { | |
// Status is the container health status | |
Status apicontainerstatus.ContainerHealthStatus `json:"status,omitempty"` | |
// Since is the timestamp when container health status changed | |
Since *time.Time `json:"statusSince,omitempty"` | |
// ExitCode is the exitcode of health check if failed | |
ExitCode int `json:"exitCode,omitempty"` | |
// Output is the output of health check | |
Output string `json:"output,omitempty"` | |
} |
amazon-ecs-agent/agent/api/container/status/containerstatus.go
Lines 43 to 50 in 883211e
const ( | |
// ContainerHealthUnknown is the initial status of container health | |
ContainerHealthUnknown ContainerHealthStatus = iota | |
// ContainerHealthy represents the status of container health check when returned healthy | |
ContainerHealthy | |
// ContainerUnhealthy represents the status of container health check when returned unhealthy | |
ContainerUnhealthy | |
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for explaining this in detail!
Summary
Move v2 metadata models to ecs-agent module. These models will be needed in ecs-agent module in future work when we move metadata endpoint handlers to ecs-agent module.
Implementation details
TaskResponse
,ContainerResponse
,LimitsResponse
, andErrorResponse
structs fromagent/handlers/v2/response.go
toecs-agent/tmds/handlers/v2/response.go
.HealthStatus
for metadata health status that replacesapicontainer.HealthStatus
fromagent/api/container
package inContainerResponse
. This is done to decouple metadata health status from API Container health status that is used in a lot of places. The new struct has the same fields except forStatus
field that has typestring
instead ofContainerHealthStatus
enum.dockerContainerHealthToV2Health
function is added toagent/handlers/v2/response.go
that convertsapicontainer.HealthStatus
to metadataHealthStatus
.TestDockerContainerHealthToV2HealthJSON
is added to ensure that the JSON representations of the two structs is the same.agent/handlers/v2/response_test.go
are updated with new asserts for health status for greater confidence in the new health status struct.Testing
New unit tests are added for the new health status struct.
In addition to automated tests, also performed manual tests to ensure that the v2, v3, and v4 metadata endpoints return the same metadata with and without the changes in this PR.
New tests cover the changes: yes
Description for the changelog
Move v2 metadata models to ecs-agent module
Licensing
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.